﻿using GameFramework;
using GameFramework.Fsm;
using GameFramework.Procedure;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;

public class ProcedureMainScene : ProcedureBase
{

    bool isEnterGame = false;
    string gameSceneName = "";

    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);
        //关闭CreatePlayer界面
        UIComponent UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
        UIFormConfig uiFormCfg01 = UIFormConfig.GetRowById((int)UIForms.CreatePlayer);
        UIForm uf = UI.GetUIForm(AppConsts.UIResPath + uiFormCfg01.AssetName);
        UI.CloseUIForm(uf);

        //打开主界面
        //UIComponent UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
        //加载UI
        UIFormConfig uiFormCfg = UIFormConfig.GetRowById((int)UIForms.Main);
        UI.OpenUIForm(AppConsts.UIResPath + uiFormCfg.AssetName, uiFormCfg.UIGroupName, this);
    }

    protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
        if(isEnterGame)
        {
            SceneComponent scene = UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();
            scene.m_NextScene = gameSceneName;
            ChangeState<ProcedureChangeScene>(procedureOwner);
        }
    }

    public void EnterGame(string sceneName)
    {
        isEnterGame = true;
        gameSceneName = sceneName;
    }

}
